import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-03-25
 * Time: 13:03
 */
public class TestDemo {
    public static void main1(String[] args) {
       int[] arr1={1,2,3,4,5};
     //  arr1 ={1,2,36};//报错
        for (int x :arr1) {
            System.out.println(x);
        }
    }
    public static void main2(String[] args) {
         int[] array = new int[10];
        System.out.println(Arrays.toString(array));
    }

    public static void main3(String[] args) {
        int[] array = {1,2,3,4,5,6,7,8,9};
        int ret = array[11];//把下标为0的元素赋值给ret
    }

    public static void main4(String[] args) {
        int[] array ={5,8,9,7,4,6,3,2,1};
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
    }

    public static void main5(String[] args) {
        int[] array ={5,8,9,7,4,6,3,2,1};
        for(int x:array) {  //for(定义的数组元素类型的变量：数组)
            System.out.print(x+" ");
        }
    }

    public static String toString1(int[] array) {
        String str ="[";
        for (int i = 0; i < array.length; i++) {
            str+=array[i];
            if(i!=array.length-1) {
                str+=",";
            }
        }
        str+="]";
        return str;
    }
    public static void main6(String[] args) {
        int[] array1=null;
        System.out.println(array1.length);
    }

    public static void main7(String[] args) {
        int[] array1 = new int[]{1,2,3,5,6};
        int[] array2 =array1;
        System.out.println(Arrays.toString(array1));
        System.out.println(Arrays.toString(array2));
    }
    public static void main8(String[] args) {
        int[] arr = {1, 2, 3};
        func(arr);
        System.out.println("arr[0] = " + arr[0]);
    }
    public static void func(int[] a) {
        a[0] = 10;
        System.out.println("a[0] = " + a[0]);
    }


    public static void func1(int[] array) {
        array = new int[]{3,4,5,6,7};
    }
    public static void func2(int[] array) {
        array[0] =1;
    }
    public static void main9(String[] args) {
        int[] array ={2,3,4,5,6};
        func1(array);
        System.out.println(Arrays.toString(array));
        func2(array);
        System.out.println(Arrays.toString(array));
    }
   public static void swap(int[] array) {
        int tmp = array[0];
        array[0] = array[1];
        array[1] = tmp;
   }
    public static void main10(String[] args) {
        int[] array = new int[]{10,20};
        swap(array);
        System.out.println(Arrays.toString(array));
    }

    public static void main11(String[] args) {
        int[][] array1 = new int[2][];//在Java中可以省略列数但不能省略行数
        array1[0]= new int[2];
        array1[1] = new int[3];
        System.out.println(Arrays.deepToString(array1));
    }

    public static void main12(String[] args) {
        int[][] array ={{1,2,3,4,5},{6,7,8},{5,6,5,2}};
        System.out.println(Arrays.deepToString(array));
        //        for (int i = 0; i < array.length; i++) {
//            for (int j = 0; j < array[i].length; j++) {
//                System.out.print(array[i][j]+" ");
//            }
//            System.out.println();
//        }
    }

    public static void main(String[] args) {
        int[][] array ={{1,2,3,4,5},{6,7,8},{5,6,5,2}};
        for (int[] tmp:array) {
            for (int x:tmp) {
                System.out.print(x+" ");
            }
            System.out.println();
        }
    }




}
